<%--
  Created by IntelliJ IDEA.
  User: 温海杰
  Date: 2020/6/17
  Time: 9:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"
         isELIgnored="false" %>
<html>
<head>
    <title>新闻管理后台</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/AdminLTE.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/_all-skins.min.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/infoStyle.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/wangEditor.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.5.1.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/wangEditor.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/editor.js"></script>

    <script type="text/javascript">
        var path = '${pageContext.request.contextPath}/news/upload'
        id = '${requestScope.get("id")}'
        $(function () {
            //表单提交
            /*
            $('#submit').click(function(){
                $('#data-form').submit();
            });

             */
            $("#newsId").val(id);
            //每10秒异步提交
            setInterval(function () {

                var title = $('#title').val();
                var body = $('#s-editor').val();
                var summaryInfo = $('#summaryInfo').val();
                var writer = $('#writer').val();
                var flag = '否';
                if ((title != "" || title != null) && (body.length>12)) {
                    $.post("${pageContext.request.contextPath}/news/updateNews", {
                        id: id,
                        title: title,
                        body: body,
                        summaryInfo: summaryInfo,
                        writer: writer,
                        releaseStatus: flag
                    }, function (data) {
                        var msg = data.msg;
                        if (mag = '发布成功') {
                            $('#success').css("display", "block");
                        }
                    }, "json")
                }
            }, 10000);
        });

        function check() {

            var r=confirm("是否确认发布？")
            if(r==false){
                return false;
            }

            var title = $('#title').val();
            var body = $('#s-editor').val();
            var summaryInfo = $('#summaryInfo').val();
            var writer = $('#writer').val();
            if(title==''||title==null){
                alert("标题不能为空！");
                return false;
            }
            if(body=='<p><br></p>'){
                alert("正文内容不能为空！");
                return false;
            }

            if(summaryInfo==''||summaryInfo==null){
                alert("摘要不能为空！");
                return false;
            }
            if(summaryInfo.length>=50){
                alert("摘要太长，请简短点！");
                return false;
            }
            if(writer==''||writer==null){
                alert("作者不能为空！");
                return false;
            }
            return true;
        }
        function exitBtn() {
            var r=confirm("确认退出？")
            if(r==true){
                window.location.href="${pageContext.request.contextPath}/admin/shutdown";
            }
        }
    </script>

</head>
<style>
    .button2{
        border-right: blue 1px solid;
        border-top: blue 1px solid;
        width: 50px;
        height: 50px;
        float:right;
        background:url('${pageContext.request.contextPath}/images/exit.png') no-repeat;
        border-style: none;
        background-size: cover;
    }
</style>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <!-- 页面头部 -->
    <!-- 页面头部 -->
    <header class="main-header">

        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" style="text-align: center;">
            <!-- Sidebar toggle button-->

            <button type="button" class="button2" onclick="exitBtn()" ></button>
        </nav>
    </header>
    <!-- 页面头部 /-->
    <!-- 导航侧栏 -->
    <aside class="main-sidebar">

        <section class="sidebar">
            <ul class="sidebar-menu">
                <li class="header">菜单</li>
                <!-- 菜单 -->
                <li id="admin-index1"><a href="${pageContext.request.contextPath}/admin/index"><i class=""></i> <span>首页</span></a></li>
                <li id="admin-index2"><a href="${pageContext.request.contextPath}/admin/showNewsInfo"><i class=""></i> <span>新闻列表</span></a></li>
                <li id="admin-index3"><a href="${pageContext.request.contextPath}/news/addNews"><i class=""></i> <span>发布新闻</span></a></li>
                <li id="admin-index4"><a href="${pageContext.request.contextPath}/admin/showDraftsInfo"><i class=""></i>
                    <span>草稿箱</span></a></li>
                <!-- 菜单 /-->
            </ul>
        </section>
    </aside>
    <!-- 导航侧栏 /-->

    <!-- 内容区域 -->
    <div class="content-wrapper">
        <section class="content">
            <form action="${pageContext.request.contextPath}/news/releaseNews" method="POST" id="data-form" onsubmit="return check()">
                <input type="text" id="newsId" name="id" style="display: none">
                <div>
                    <label>标题</label><br>
                    <input type="text" id="title" name="title" style="width:100%"/>
                </div>
                <div>
                    <label>内容</label>
                    <div id="editor">
                    </div>
                    <input name="body" id="s-editor" type="text" style="display:none;"/>
                </div>
                <div>
                    <label>摘要</label>
                    <div>
                        <textarea style="width:100%;height:100px;resize:none;" name="summaryInfo" id="summaryInfo"></textarea>
                    </div>
                </div>

                <div>
                    <label>作者</label>
                    <input type="text" name="writer" id="writer"/><br>
                </div>
                <br>
                <div>
                    <input class="button" type="submit" value="发布" style="background:grey;" id="submit"/>
                    <label style="float: right;display:none;" id="success">自动保存成功！</label>
                </div>
                <input type="tetx" name="releaseStatus" value="是" style="display: none">
            </form>
            <!-- /.error-page -->
        </section>
        <!-- /.content -->
    </div>
    <!-- 内容区域 /-->


    <!-- 底部导航 -->
    <footer class="main-footer">
        <strong>Copyright &copy; web第三小组</strong>
    </footer>
    <!-- 底部导航 /-->
</div>
</body>
<script>

</script>
</html>